package com.d3.pomodoro

import android.app.Activity
import android.app.Application
import com.orhanobut.hawk.Hawk
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import java.util.ArrayList

class AppApplication : Application() {
    var mActivityList = ArrayList<Activity>()

    companion object {
        private var instance: AppApplication? = null
        fun getInstance(): AppApplication {
            checkNotNull(instance) { "Application is not created." }
            return instance!!
        }
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        //init Hawk
        Hawk.init(this).build()
        Logger.addLogAdapter(object : AndroidLogAdapter() {
            override fun isLoggable(priority: Int, tag: String?): Boolean {
                return BuildConfig.DEBUG
            }
        })
    }


    /**
     * 添加Activity到容器中
     *
     * @param activity 当前实例
     */
    fun addActivity(activity: Activity?) {
        if (activity != null) {
            mActivityList.add(activity)
        }
    }

    /**
     * 移除容器中的Activity
     *
     * @param activity 当前实例
     */
    fun removeActivity(activity: Activity?) {
        if (activity != null) {
            mActivityList.remove(activity)
        }
    }


}